<template>
	<view >
		<uni-forms ref="form" :modelValue="form" :rules="rules" :label-width="80" style="background-color: #fff;">
			<uni-forms-item label="车牌号" required name="carNo">
				<vnp-input style="width: 100%;" v-model="form.carNo"></vnp-input>
			</uni-forms-item>
			<uni-forms-item label="标记类型" required name="vipType">
				<uni-data-select v-model="form.vipType" :localdata="projectTypeOptions" ></uni-data-select>
			</uni-forms-item>
			<view v-if="form.vipType == 'temporary'">
				<uni-forms-item label="开始日期" required name="startDate">
					<date-input v-model="form.startDate"></date-input>
				</uni-forms-item>
				<uni-forms-item label="到期日期" required name="endDate">
					<date-input v-model="form.endDate"></date-input>
				</uni-forms-item>
			</view>
		</uni-forms>
	</view>
</template>

<script>
	import { getVip, addVip, updateVip } from "@/api/control/vip";
	import VnpInput from '@/components/vant-number-plate/vnp-input';
	import dateInput from '@/components/date-input/index'
	import {  getDicts } from "@/api/system/dict/data"
	export default {
		components: {
			'vnp-input': VnpInput,dateInput
		},
		data() {
			return {
				form:{
					id: null,
					carNo: "",
					vipType: null,
					startDate: null,
					endDate: null,
					remark: null
				},
				rules:{
					
				},
				projectTypeOptions:[]
			}
		},
		onLoad(options) {
			getDicts('vip_type').then(res => {
				this.projectTypeOptions = res.data
				this.projectTypeOptions.forEach(d => {
					d.value = d.dictValue
					d.text = d.dictLabel
				})
			})
			if(options.id > 0 ) this.queryById(options.id)
		},
		methods: {
			queryById(id) {
				getVip(id).then(res =>{
					this.form = res.data
				})
			},
			onNavigationBarButtonTap() {
				this.submitForm()
			},
			submitForm() {
			 this.$refs.form.validate(['id'],(err,form)=>{
				if (!err) {
				  if (this.form.id != null) {
					updateVip(this.form).then(response => {
					  this.$modal.msgSuccess("修改成功");
					  this.isEdit = false
					});
				  } else {
					addVip(this.form).then(response => {
					  this.$modal.msgSuccess("新增成功");
					  this.isEdit = false
					});
				  }
				}
			  });
			},
		}
	}
</script>

<style scoped>
page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		background-color: #fff;
		min-height: 100%;
		height: auto;
	}
</style>
